/*
 * Copyright (c) 2017. danlu.com Co.Ltd. All rights reserved.
 */

package cn.com.dhc.danlu.dlware.net;

import com.danlu.lib.net.BuildConfig;
import com.danlu.lib.net.exception.ExceptionEngine;
import com.danlu.lib.net.exception.ObviousException;

import rx.Subscriber;

/**
 * author: wuhaiyang(<a href="mailto:wuhaiyang@danlu.com">wuhaiyang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-02-07 上午10:53<br/>
 * <p>
 * 基类回请求callback
 * </p>
 */
public abstract class BaseObserver <T> extends Subscriber<T> {
    @Override
    public void onError(Throwable e) {
        if (BuildConfig.DEBUG) {
            e.printStackTrace();
        }
        if (e instanceof ObviousException) {
            onError((ObviousException) e);
        } else {
            onError(ExceptionEngine.handleException(e));
        }
    }

    /**
     * 错误回调
     */
    protected abstract void onError(ObviousException ex);
}
